CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -I.

# 源文件
SRCS = FileManager.cpp Page.cpp BufferManager.cpp StorageManager.cpp SystemCatalog.cpp test_page_system.cpp interactive_demo.cpp simple_persistence_test.cpp
OBJS = $(SRCS:.cpp=.o)
TARGET = test_page_system
TARGET_INTERACTIVE = interactive_demo
TARGET_PERSISTENCE = simple_persistence_test

# 默认目标
all: $(TARGET) $(TARGET_INTERACTIVE) $(TARGET_PERSISTENCE)

# 主测试程序
$(TARGET): FileManager.o Page.o BufferManager.o StorageManager.o SystemCatalog.o test_page_system.o
	$(CXX) $(CXXFLAGS) -o $@ $^

# 交互式演示程序 (不包含SystemCatalog，保持简单)
$(TARGET_INTERACTIVE): FileManager.o Page.o BufferManager.o StorageManager.o interactive_demo.o
	$(CXX) $(CXXFLAGS) -o $@ $^

# 持久性测试程序
$(TARGET_PERSISTENCE): FileManager.o Page.o BufferManager.o StorageManager.o SystemCatalog.o simple_persistence_test.o
	$(CXX) $(CXXFLAGS) -o $@ $^

# 编译规则
%.o: %.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@

# 清理
clean:
	rm -f $(OBJS) $(TARGET) $(TARGET_INTERACTIVE) $(TARGET_PERSISTENCE)

# 运行测试
run: $(TARGET)
	./$(TARGET)

# 运行交互式演示
interactive: $(TARGET_INTERACTIVE)
	./$(TARGET_INTERACTIVE)

# 运行持久性测试
persistence: $(TARGET_PERSISTENCE)
	./$(TARGET_PERSISTENCE)

.PHONY: all clean run interactive persistence